CFLAGS = -Wall -fpic -coverage -lm

rngs.o: rngs.h rngs.c
	gcc -c rngs.c -g  $(CFLAGS)

dominion.o: dominion.h dominion.c rngs.o
	gcc -c dominion.c -g  $(CFLAGS)

playdom: dominion.o playdom.c
	gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)

testDrawCard: testDrawCard.c dominion.o rngs.o
	gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

badTestDrawCard: badTestDrawCard.c dominion.o rngs.o
	gcc -o badTestDrawCard -g  badTestDrawCard.c dominion.o rngs.o $(CFLAGS)

testBuyCard: testBuyCard.c dominion.o rngs.o
	gcc -o testBuyCard -g  testBuyCard.c dominion.o rngs.o $(CFLAGS)

testAll: dominion.o testSuite.c
	gcc -o testSuite testSuite.c -g  dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
	gcc -c interface.c -g  $(CFLAGS)

player: player.c interface.o
	gcc -o player player.c -g  dominion.o rngs.o interface.o $(CFLAGS)

unittestresults.out: dominion.c rngs.c
	gcc $(CFLAGS) dominion.c rngs.c unittest1.c -o unittest1
	gcc $(CFLAGS) dominion.c rngs.c unittest2.c -o unittest2
	gcc $(CFLAGS) dominion.c rngs.c unittest3.c -o unittest3
	gcc $(CFLAGS) dominion.c rngs.c unittest4.c -o unittest4
	gcc $(CFLAGS) dominion.c rngs.c cardtest1.c -o cardtest1
	gcc $(CFLAGS) dominion.c rngs.c cardtest2.c -o cardtest2
	gcc $(CFLAGS) dominion.c rngs.c cardtest3.c -o cardtest3
	gcc $(CFLAGS) dominion.c rngs.c cardtest4.c -o cardtest4
	
	./unittest1 >> coverage2.txt
	gcov unittest1 >> coverage2.txt
	./unittest2 >> coverage2.txt
	gcov unittest2 >> coverage2.txt
	./unittest3 >> coverage2.txt
	gcov unittest3 >> coverage2.txt
	./unittest4 >> coverage2.txt
	gcov unittest4 >> coverage2.txt

	./cardtest1 >> coverage2.txt
	gcov cardtest1 >> coverage2.txt
	./cardtest2 >> coverage2.txt
	gcov cardtest2 >> coverage2.txt
	./cardtest3 >> coverage2.txt
	gcov cardtest3 >> coverage2.txt
	./cardtest4 >> coverage2.txt
	gcov cardtest4 >> coverage2.txt

randomtestadventurer.out: dominion.c rngs.c dominion.h rngs.h
	gcc $(CFLAGS) dominion.c rngs.c interface.c randomtestadventurer.c -o randomtestadventurer

randomtestcard.out: dominion.c rngs.c
	gcc $(CFLAGS) dominion.c rngs.c interface.c randomtestcard.c -o randomtestcard

testdominion.out: dominion.c rngs.c tdInterface.c
	gcc $(CFLAGS) dominion.c rngs.c tdInterface.c testdominion.c -o testdominion
	for ((i=1; i<=10; i++)); do \
	 timeout -s TERM 10s ./testdominion $$i >> testdominion.out; \
	done

shuffleTest.out: dominion.c rngs.c
	gcc $(CFLAGS) dominion.c rngs.c shuffleTest.c -o shuffleTest
	./shuffleTest

buyCardTest.out: dominion.c rngs.c
	gcc $(CFLAGS) dominion.c rngs.c buyCardTest.c -o buyCardTest
	./buyCardTest

gainCardTest.out: dominion.c rngs.c
	gcc $(CFLAGS) dominion.c rngs.c gainCardTest.c -o gainCardTest
	./gainCardTest

drawCardTest.out: dominion.c rngs.c
	gcc $(CFLAGS) dominion.c rngs.c drawCardTest.c -o drawCardTest
	./drawCardTest

playerHandTest.out: dominion.c rngs.c
	gcc $(CFLAGS) dominion.c rngs.c playerHandTest.c -o playerHandTest
	./playerHandTest

all: playdom player testDrawCard testBuyCard badTestDrawCard

clean:
	rm -f *.o playerHandTest drawCardTest gainCardTest buyCardTest shuffleTest testdominion randomtestcard randomtestadventurer unittest1 unittest2 unittest3 unittest4 cardtest1 cardtest2 cardtest3 cardtest4 playdom.exe playdom test.exe test player player.exe testDrawCard testDrawCard.exe testBuyCard testBuyCard.exe badTestDrawCard badTestDrawCard.exe *.gcov *.gcda *.gcno *.so
